import { ccs } from "../../util/services";
import { game } from "../control/game";
import { playerClass } from "./playerModel";

const {ccclass, property} = cc._decorator;
//游戏控制类
export type gameTime = {
    day: number,
    hour: number,
    min: number,
    week: number,
    year: number,
    month: number,
}
@ccclass
export class timeClass {

    // timer: 0;
    gameTime = {
        day: 1,
        hour: 1,
        min: 1,
        week: 1,
        year: 1,
        month: 1,
    }
    weekArr = [ '一', '二', '三', '四', '五', '六','日'];
    //事件时间增加
    addTime(count: number, player?: playerClass, time: keyof gameTime = "month") {
        this.gameTime[time] += count;
        this.formatTime(); //更新时间
        ccs.mainEmitter.emit("updateTime"); //更新时间
    }
    formatTime() {
        
        if(this.gameTime.month > 12) {
            this.gameTime.year += Math.floor(this.gameTime.month / 12);
            this.gameTime.month = 1;
            game.playerMgr.addAge();
        }
    }
    getTime() {
        return `${this.gameTime.year}年${this.gameTime.month}月${this.gameTime.day}日`;
    }
}